package com.example.stugradeapp

import android.content.Intent
import android.icu.text.CaseMap
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import kotlinx.android.synthetic.main.activity_add.*
import kotlinx.android.synthetic.main.activity_update.*

class updateActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_update)
        var id = intent.getStringExtra("id").toString()
        var title = intent.getStringExtra("title").toString()
        var author = intent.getStringExtra("author").toString()
        var pages = intent.getStringExtra("pages").toString()

        title_input2.setText(title)
        author_input2.setText(author)
        pages_input2.setText(pages)
        update_button.setOnClickListener{
            val myDB = MyDatabaseHelper(this)
            myDB.updateData(id.toInt(),title_input2.text.toString(),author_input2.text.toString(),pages_input2.text.toString().toInt())
            val intent  = Intent(this,MainActivity::class.java)
            startActivity(intent)
        }
        delete_button.setOnClickListener {
            val myDB = MyDatabaseHelper(this)
            myDB.deleteOneRow(id.toInt())
            val intent  = Intent(this,MainActivity::class.java)
            startActivity(intent)
        }
        var ab = supportActionBar
        ab?.title=title
    }
//    fun getData(){
//
//    }

//    fun confirmDelete(){
//        val builder = AlertDialog.Builder(this)
//        builder.setTitle("删除"+title+"?")
//        builder.setMessage("你确定要删除"+title+"吗？")
//        builder.
//    }
}